#include<iostream>
#include<windows.h>
#include<cstdlib>
//要注意构造函数调用的次数比较多
using namespace std;

class Point
{
private:
	int x, y;
public:
	Point()
	{
		x = 0;
		y = 0;
		cout << "The constructer was called!" << endl;

	}
	Point(int a,int b=0)
	{
		this->x = a;
		this->y = b;
		cout << "The constructer was called!" << endl;

	}
	Point(const Point& r)
	{
		this->x = r.x;
		this->y = r.y;
		cout << "The constructer was called!" << endl;

	}

	Point operator+(Point &point1)
	{
		Point p;
		p.x=x + point1.x;
		p.y=y + point1.y;
		return p;
	}

	friend Point operator-(Point &a1, Point &a2);

	~Point()
	{
		cout << "The distructer was called!"<<endl;
	}
	
	//普通函数部分
	void OutValue()
	{
		cout << "x=" << x<<endl;
		cout << "y=" << y << endl;

	}



};

Point operator-(Point &a1, Point &a2)
{
	Point A1(0,0);
	A1.x = a1.x - a2.x;
	A1.y = a1.y - a2.y;
	return A1;
}

int main()
{
	Point p1(1,2), p2(3,6), p3,p4;
	p3 = p1.operator+(p2);
	p4 = p2 - p1;

	cout << "p3:" << endl;
	p3.OutValue();

	cout << "p4:" << endl;
	p4.OutValue();

	system("pause");
	return 0;
}